package com.oracle.oa.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;
import org.hibernate.criterion.DetachedCriteria;

import com.opensymphony.xwork2.ActionSupport;
import com.oracle.oa.biz.OperatelogBiz;
import com.oracle.oa.biz.impl.OperatelogBizImpl;
import com.oracle.oa.entity.Loginlog;
import com.oracle.oa.entity.Operatelog;
import com.oracle.oa.util.PageBean;

public class OperateLogAction extends ActionSupport implements SessionAware {

	OperatelogBiz oBiz;
	public Map<String, Object> session;
	public Operatelog operatelog=new Operatelog();
	List logvalue=new ArrayList();
	
	//分页需要的属性
	Class clz=Operatelog.class;
	public String currentPage;
	public PageBean pageBean=new PageBean();
	public List<Operatelog> operateloglist=new ArrayList<Operatelog>();

	public String getAll() {
		/*List<Operatelog> operateloglist=oBiz.getAll(Operatelog.class);
		session.put("operateloglist", operateloglist);
		return SUCCESS;*/
		DetachedCriteria dc = DetachedCriteria.forClass(clz);
		oBiz.splitPage1(pageBean, dc, clz);
		int current=1;
		if(currentPage!=null){
			current=Integer.parseInt(currentPage);
			if(current<1){
				current=1;
			}
			if(current>pageBean.getTotalPage()){
				current=pageBean.getTotalPage();
			}
			pageBean.setCurrentPage(current);
		}
		oBiz.splitPage1(pageBean, dc, clz);
		operateloglist=pageBean.getList();
		session.put("operateloglist", operateloglist);
		return SUCCESS;
	}

	public String save() {
		oBiz.save(operatelog);
		operatelog=new Operatelog();
		getAll();
		return SUCCESS;
	}
	public String delete(){
		/*OperatelogBizImpl.add("删除", "删除操作日志");*/
		for (int i = 0; i < logvalue.size(); i++) {
			operatelog=new Operatelog();
			operatelog=(Operatelog) oBiz.getById(Operatelog.class, Long.parseLong(logvalue.get(i).toString()));
			oBiz.delete(operatelog);
		}
		getAll();
		return SUCCESS;
	}
	public String one(){
		operatelog= (Operatelog) oBiz.getById(Operatelog.class, operatelog.getOperateid());
		return SUCCESS;
	}
	public String update(){
		oBiz.update(operatelog);
		operatelog=new Operatelog();
		getAll();
		return SUCCESS;
	}

	public void setSession(Map<String, Object> arg0) {
		this.session = arg0;
	}

	public Operatelog getOperatelog() {
		return operatelog;
	}

	public void setOperatelog(Operatelog operatelog) {
		this.operatelog = operatelog;
	}

	

	public List getLogvalue() {
		return logvalue;
	}

	public void setLogvalue(List logvalue) {
		this.logvalue = logvalue;
	}

	public OperatelogBiz getoBiz() {
		return oBiz;
	}

	public void setoBiz(OperatelogBiz oBiz) {
		this.oBiz = oBiz;
	}
	
	
	

	

}
